package org.luxor.commons.storage.client.disk;

import org.luxor.commons.storage.client.AbstractStorageProperties;
import org.luxor.commons.storage.config.HttpConfig;
import org.luxor.commons.storage.config.ThumbImageConfig;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

/**
 * 本地磁盘配置
 *
 * @author Mr.yan @date 2019/12/15
 */
@ConfigurationProperties(prefix = DiskProperties.PREFIX)
public class DiskProperties extends AbstractStorageProperties {

    public static final String PREFIX = "spring.storage.disk";

    final Boolean DEFAULT_ENABLED = Boolean.FALSE;
    final Integer DEFAULT_CHUNK_SIZE = 5;
    final Integer DEFAULT_DOWNLOAD_CHUNK_SIZE = 100;
    final HttpConfig DEFAULT_HTTP = new HttpConfig();
    final ThumbImageConfig DEFAULT_THUMB_IMAGE = new ThumbImageConfig();

    final String DEFAULT_DATA_DIR = "/tmp/storage/data";

    /**
     * 是否启用
     */
    private boolean enabled;

    /**
     * 分块大小
     */
    private Integer chunkSize;
    private Integer downloadChunkSize;

    /**
     * 缩略图配置
     */
    @NestedConfigurationProperty
    private ThumbImageConfig thumbImage;

    /**
     * 防盗链配置
     */
    @NestedConfigurationProperty
    private HttpConfig http;


    /**
     * 文件存储位置
     */
    private String dataDir;


    public DiskProperties() {
        super();
        this.enabled = DEFAULT_ENABLED.booleanValue();
        this.chunkSize = DEFAULT_CHUNK_SIZE;
        this.downloadChunkSize = DEFAULT_DOWNLOAD_CHUNK_SIZE;
        this.thumbImage = DEFAULT_THUMB_IMAGE;
        this.http = DEFAULT_HTTP;

        this.dataDir = DEFAULT_DATA_DIR;
    }

    public String getDataDir() {
        return this.dataDir;
    }

    public void setDataDir(String dataDir) {
        this.dataDir = dataDir;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }


    public Integer getChunkSize() {
        return chunkSize;
    }

    public void setChunkSize(Integer chunkSize) {
        this.chunkSize = chunkSize;
    }

    public Integer getDownloadChunkSize() {
        return downloadChunkSize;
    }

    public void setDownloadChunkSize(Integer downloadChunkSize) {
        this.downloadChunkSize = downloadChunkSize;
    }

    @Override
    public ThumbImageConfig getThumbImage() {
        return thumbImage;
    }

    public void setThumbImage(ThumbImageConfig thumbImage) {
        this.thumbImage = thumbImage;
    }

    @Override
    public HttpConfig getHttp() {
        return http;
    }

    public void setHttp(HttpConfig http) {
        this.http = http;
    }
}
